﻿using System;
using System.Collections.Generic;
using Lottery.App.Model;
using Lottery.App.DAL;

namespace UI
{
    internal class Checker
    {
        public static bool Valid()
        {
            bool isValid = CheckDate() && CheckCpu();

            if (!isValid)
            {
                //Lottery.App.DAL.RecordDao dao = new Lottery.App.DAL.RecordDao();
                //IList<RecordInfo> list = dao.GetAllObjects();

                //dao.BeginTransaction();
                //foreach (RecordInfo item in list)
                //{
                //    dao.Delete(item);
                //}
                //dao.CommitChanges();
            }

            return isValid;
        }

        public static bool CheckDate()
        {
            //return DateTime.Now < new DateTime(2013, 1, 31);
            const string url = "http://www.kkcai.net/try.txt";

            try
            {
                string resp = new Lottery.App.Core.WebUtils().DoGet(url, null);

                return resp == "true";
            }
            catch
            {
                return false;
            }
            
        }

        public static bool CheckCpu()
        {
            return true;
            string cpu = Lottery.App.Utility.CryptHelper.GetCpuSerialNumber();

            string cfg = new ConfigDao().Get(1).Key;

            return cpu == Lottery.App.Utility.CryptHelper.DeCryptDES(cfg);
        }
    }
}
